/*测试数据*/
var testdata={
		id: 1,
		userId: 2322,
		phone: 18817802281,
		realName: 'lisd',
		address: '上海市浦东新区',
		shoppingAddress: '上海市浦东新区',
		createTime: 1502937009,
		userMoney: 2366,
		taxType: '个人', //公司、个人
		taxCompany: '上海煜众网络科技有限公司',
		taxId: 'CX343344343',
		taxPhone: '18817802221',
		taxAddress: '上海工商银行宝山支行',
		taxBankId: '33222331453233434',
		taxBankName: '上海工商银行宝山支行'
	};


$(function(){
	getUsMessage();
	$("#btnEditMes").on('click',function(){
		$("#btnEditMes").hide();
		$("#mesList").hide();
		$("#editForm").show();
	});
	$("#btnReback").on('click',function(){
		$("#btnEditMes").show();
		$("#mesList").show();
		$("#editForm").hide();
	});
	$("#btnSaveEdit").on('click',function(){
		saveEditMes();
	});
});
/*加载个人信息*/
function getUsMessage(){
    var tgid = localStorage.getItem("userID");
    if(tgid!=null && tgid!=""){
        $.post(
            gobalServer+"user/selectOne",
            {"userId":tgid},
            function(backData){
                if(backData.statusCode==200){
                    var datarow=backData.object;
                    if(datarow!=null){
                        $("#manageContent").attr({"tgid":datarow.userId});
                        $("#phone").text(datarow.phone);
                        $("#realName").text(datarow.realName);
                        $("#userMoney").html("￥"+datarow.userMoney);
                        $("#address").text(datarow.address);
                        $("#shoppingAddress").text(datarow.shoppingAddress);
                        $("#taxType").text(datarow.taxType);
                        $("#taxCompany").text(datarow.taxCompany);
                        $("#taxId").text(datarow.taxId);
                        $("#taxPhone").text(datarow.taxPhone);
                        $("#taxAddress").text(datarow.taxAddress);
                        $("#taxBankId").text(datarow.taxBankId);
                        $("#taxBankName").text(datarow.taxBankName);
                        $("#memberAddress").val(datarow.address);
                        $("#commonAddress").val(datarow.shoppingAddress);
                        $("#taxTypeED").val(datarow.taxType);
                        $("#taxCompanyED").val(datarow.taxCompany);
                        $("#taxIdED").val(datarow.taxId);
                        $("#taxPhoneED").val(datarow.taxPhone);
                        $("#taxAddressED").val(datarow.taxAddress);
                        $("#taxBankIdED").val(datarow.taxBankId);
                        $("#taxBankNameED").val(datarow.taxBankName);
                    }else{
                        consoleMes($("#manageContent"),3000,"warning","无法获取个人信息，可能账号未登录，请重新登录！");//success、info、warning、danger
                        setTimeout(function () {
                            window.location.href=gobalWeb+"login.html";
                        }, 2500);
                    }

                }else{
                    consoleMes($("#manageContent"),3000,"warning",backData.msg);//success、info、warning、danger
                }
            }
        );
	}else{
        consoleMes($("#manageContent"),3000,"warning","无法获取个人信息，可能账号未登录，请重新登录！");//success、info、warning、danger
        setTimeout(function () {
            window.location.href=gobalWeb+"login.html";
        }, 2500);
    }
};
/*保存修改信息*/
function saveEditMes(){
	var tgid=$("#manageContent").attr("tgid");
	var memberAddress=$("#memberAddress").val().trim();
	var commonAddress=$("#commonAddress").val().trim();
	var taxType=$("#taxTypeED").val().trim();
	var taxCompany=$("#taxCompanyED").val().trim();
	var taxId=$("#taxIdED").val().trim();
	var taxPhone=$("#taxPhoneED").val().trim();
	var taxAddress=$("#taxAddressED").val().trim();
	var taxBankId=$("#taxBankIdED").val().trim();
	var taxBankName=$("#taxBankNameED").val().trim();
	/*consoleMes($("#manageContent"),2000,"success","信息修改成功，正在刷新！");//success、info、warning、danger
	setTimeout(function () {
    	window.location.reload();
    }, 2500);*/
    if(tgid!=null && tgid!=""){
        $.post(
            gobalServer+"user/update",
            {"userId":tgid,"address":memberAddress,"shoppingAddress":commonAddress,
                "taxType":taxType,"taxCompany":taxCompany,"taxId":taxId,"taxPhone":taxPhone,
                "taxAddress":taxAddress,"taxBankId":taxBankId,"taxBankName":taxBankName},
            function(backData){
                if(backData.statusCode==200){
                    consoleMes($("#manageContent"),2000,"success","信息修改成功，正在刷新！");//success、info、warning、danger
                    setTimeout(function () {
                        window.location.reload();
                    }, 2500);

                }else{
                    consoleMes($("#manageContent"),3000,"warning",backData.msg);//success、info、warning、danger
                }
            }
        );

    }else{
		consoleMes($("#manageContent"),2000,"warning","无法提交，请刷新页面重试！");
	}
};